<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%@ include file="/WEB-INF/pages/common/dialog.jsp"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>

	<%Long offset = (Long)request.getAttribute("offset");%>

    <table class="${tableclass}" style="width: 100%">
    <thead>
    	<tr><th><strong class="am-text-primary am-text-lg">用户管理</strong> /  用户信息管理</th></tr>
    </thead>
    <tbody><tr><td>
 <div align="left" style="padding: 3px">
 
 <div style="margin-left: 0.5rem">
	<div class="seller_list_title">
         <ul class="seller_title_ul am-tabs-nav am-nav am-nav-tabs">
         	<li <c:if test="${empty haveShop}"> class="am-active"</c:if> ><i></i><a href="<ls:url address="/admin/system/userDetail/query"/>">所有用户</a></li>
        	<li <c:if test="${haveShop eq '0'}"> class="am-active"</c:if> ><i></i><a href="<ls:url address="/admin/system/userDetail/query?haveShop=0"/>">普通用户</a></li>
        	<li <c:if test="${haveShop eq '1'}"> class="am-active"</c:if> ><i></i><a href="<ls:url address="/admin/system/userDetail/query?haveShop=1"/>">商家</a></li>
        </ul>
     </div>
 </div>
 
<form:form  action="${contextPath}/admin/system/userDetail/query" id="form1" name="form1" method="get">
<input type="hidden" id="curPageNO" name="curPageNO" value="${curPageNO}">
<div class="criteriaDiv2" style="margin: 3px">
			<input class="${inputclass}" type="text" name="userName" maxlength="50" value="${userDetail.userName}"  placeholder="请输入用户名搜索"/>
				<input class="${inputclass}" type="text" name="userMail" maxlength="50" value="${userDetail.userMail}" placeholder="请输入邮件搜索"/>
				<input class="${inputclass}" type="text" name="realName" maxlength="50" value="${userDetail.realName}" placeholder="请输入姓名搜索"/>

</div>

<div class="criteriaDiv2" style="margin: 3px">
				<input class="${inputclass}" type="text" name="nickName" maxlength="50" value="${userDetail.nickName}" placeholder="请输入昵称搜索"/>
				<input class="${inputclass}" type="text" name="userMobile" maxlength="50" value="${userDetail.userMobile}" placeholder="请输入手机号码搜索"/>			
				<input type="hidden"   id="haveShop" name="haveShop"  />
			&nbsp;状态 
			<select id="enabled" name="enabled" class="${selectclass}">
					<option value="">请选择</option>	
			    	<option value="1">有效</option>	
	      			<option value="0" >无效</option>
			</select>
			<input class="${btnclass}" type="button" onclick="search()" value="搜索"/>
			<input class="${btnclass}" type="button" value="导出搜索数据" onclick="exportUser();"/>
</div>

				
						
</form:form>
 </div>
 </td></tr></tbody>
    </table>

<div align="center">
        <%@ include file="/WEB-INF/pages/common/messages.jsp"%>
    <display:table name="list" requestURI="/admin/system/userDetail/query" id="item"
         export="false"  class="${tableclass}"  sort="external">
      <display:column style="width:60px;vertical-align: middle;text-align: center;" title="全选 <input type='checkbox'  id='checkbox' name='checkbox' onClick='javascript:selAll()' />"><%=offset++%> <input type="checkbox" name="strArray" value="${item.userId}" arg="${item.userName}"/></display:column>
      <display:column title="用户名" style="width:130px;" sortable="true" sortName="u.user_name" >
      		<a href="<ls:url address='/admin/userinfo/userDetail/${item.userId}'/>">${item.userName }</a>
      </display:column>
      <display:column title="昵称" property="nickName" sortable="true" sortName="u.nick_name"  style="max-width:150px; word-wrap: break-word;" ></display:column>
    <c:if test="${haveShop eq '1'}">
      <display:column title="店铺名" style="width:130px;"><a href="${contextPath}/admin/shopDetail/load/${item.shopId}">${item.siteName}</a></display:column>
    </c:if>
      <display:column title="邮件" property="userMail" style="width:130px;"></display:column>
      <display:column title="手机号码" property="userMobile"  style="min-width:130px;" ></display:column>
      <display:column title="用户类型"  style="min-width:100px;" >
      		<c:choose>
      				<c:when test="${empty item.shopId}">普通用户</c:when>
      				<c:otherwise>商家</c:otherwise>
      		</c:choose>
      </display:column>
      <display:column title="预存款"  style="min-width:100px;" ><fmt:formatNumber type="CURRENCY" value="${item.availablePredeposit}" pattern="#.##" maxFractionDigits="2" /></display:column>
      <display:column title="金币" property="userCoin"></display:column>
       <display:column title="状态" sortable="true" sortName="s.enabled"  >
       <c:choose>
       		<c:when test="${item.enabled == 1}">有效</c:when>
       		<c:otherwise><font color="red">无效</font></c:otherwise>
       </c:choose>
      </display:column>
	      <display:column title="操作" media="html" style="width:190px; min-width:190px;">
		      <%--<ls:auth ifAnyGranted="F_VIEW_USER">
		         <a href='${contextPath}/admin/system/userDetail/load/${item.userName}' title="查看用户${item.userName}信息"><img alt="查看用户${item.userName}信息" src="${contextPath}/resources/common/images/ind_left_login.gif"></a>
		      </ls:auth>
		     --%>
		  	 	<div class="am-btn-toolbar">
			      <div class="am-btn-group am-btn-group-xs">
				     <button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="window.location.href='${contextPath}/admin/userinfo/userDetail/${item.userId}'" ><span class="am-icon-search"></span>查看</button>
				     
				     
				<div class="am-dropdown" data-am-dropdown>
	                <button class="am-btn am-btn-default am-btn-xs am-dropdown-toggle" data-am-dropdown-toggle><span class="am-icon-cog"></span> <span class="am-icon-caret-down"></span></button>
	                <ul class="am-dropdown-content">
	                  <li><a href="${contextPath}/admin/member/user/roles/${item.userId}?appNo=FRONT_END">1. 查看用户角色</a></li>
	                  <li><a href="${contextPath}/admin/member/user/functions/${item.userId}?appNo=FRONT_END">2. 查看用户权限</a></li>
	                  <li><a href="<ls:url address='/admin/member/user/update/${item.id}?appNo=FRONT_END'/>">3. 修改密码</a></li>
	                  <li><a href="<ls:url address='/admin/sendmessage/load/${item.userId}?type=1'/>">4. 发送站内信</a></li>
	                  <li><a href="<ls:url address='/admin/sendmessage/load/${item.userId}?type=2'/>">5. 发送邮件</a></li>
	                <%--   <li><a href="<ls:url address='/admin/sendmessage/load/${item.userId}?type=3'/>">6. 发送短信</a></li> --%>
<%-- 	                  <li onclick="coinPage('${item.userId}');"><a href="javascript:void(0);">6. 金币充值</a></li> --%>
	                 </ul>
              </div>
              <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="javascript:confirmDelete('${item.userId}','${item.userName}', false)"><span class="am-icon-trash-o"></span> 删除</button>
				  </div>
			 	</div>
		 </display:column>
    </display:table> 
                      <input class="${btnclass}" type="button" value="刪除" style="float: left" onclick="return deleteAction();"/>   
    <ls:page pageSize="${pageSize }"  total="${total}" curPageNO="${curPageNO }"  type="default"/>
    </div>
    
    <script language="JavaScript" type="text/javascript">

 function deleteAction(){
	//获取选择的记录集合
	selAry = document.getElementsByName("strArray");
	if(!checkSelect(selAry)){
	 window.alert('删除时至少选中一条记录！');
	 return false;
	}
	if(confirm("确定要删除吗？")){
	for(i=0;i<selAry.length;i++){
	  if(selAry[i].checked){
		var userId = selAry[i].value;
		var userName = selAry[i].getAttribute("arg");
			deleteUserDetail(userId,userName, true);
		 }
		}
	}
    window.location = '${contextPath}/admin/system/userDetail/query';
	return true;
}

  function confirmDelete(userId,userName)
	{
	   if(confirm("删除后无法恢复数据， 确定要删除用户 "+userName+"？")){
	   	deleteUserDetail(userId,userName, false);
	   }
	}
	
  function deleteUserDetail(userId,userName, multiDel) {
		    var data = {
	   				"userId":userId,
                	"userName": userName
                };
    			jQuery.ajax({
				url:"${contextPath}/admin/system/userDetail/delete" , 
				data: data,
				type:'post', 
				async : false, //默认为true 异步   
			    dataType : 'html', 
				error: function(jqXHR, textStatus, errorThrown) {
			 		// alert(textStatus, errorThrown);
				},
				success:function(retData){
				if(!multiDel){
						 if(retData == null ||  retData == ''){
					 		 window.location = '${contextPath}/admin/system/userDetail/query';
				       }else{
					 		 //alert(retData.substring(6, retData.length)) ;
					 		// art.dialog.tips(retData.substring(6, retData.length));
					 		 art.dialog.tips(retData);
				       }
					}
				}
				});
	}
	
    function pager(curPageNO){
            document.getElementById("curPageNO").value=curPageNO;
            document.getElementById("form1").submit();
        }
        
     function initVal(enabledValue,haveShopValue){
        	jQuery("#enabled").val(enabledValue);
        	jQuery("#haveShop").val(haveShopValue);
		}	
		
	jQuery(document).ready(function() {
        	initVal( '${userDetail.enabled}', '${haveShop}');
        	highlightTableRows("item"); 
	});
		
	//金币充值页面
	function coinPage(userId){
    	art.dialog.open("${contextPath}/admin/coin/rechargePage?userId="+userId,{
        	width: 420,
        	height: 300,
	    	drag: true,
	    	resize: true,
	    	fixed: true,
        	title:"金币充值",
        	lock: true,
        	close:function(){
        		var win = art.dialog.open.origin;
				win.location.reload();
        	}
        });
    }
    
    
    function exportUser(){
    	var haveShop="${haveShop}";
    	var userName="${userDetail.userName}";
    	var userMail="${userDetail.userMail}";
    	var realName="${userDetail.realName}";
    	var nickName="${userDetail.nickName}";
    	var userMobile="${userDetail.userMobile}";
    	var enabled="${userDetail.enabled}";
    	var data=[]; 
    	data.push(haveShop);
    	data.push(userName);
    	data.push(userMail);
    	data.push(realName);
    	data.push(nickName);
    	data.push(userMobile);
    	data.push(enabled);
    	var jsondata=JSON.stringify(data);
    	window.location.href="${contextPath}/admin/system/userDetail/export?data="+jsondata;
    }
    
    function search(){
	  	$("#form1 #curPageNO").val("1");//只要是搜索,都是从第一页开始查
	  	$("#form1")[0].submit();
	}
</script>

